package march.test_3_7;

public class Gift {
    public int getValue(int[] gifts, int n) {
        // write code here
        int tmp = gifts[0];
        int count = 0;
        for(int i = 0; i < n; i++) {
            if(count == 0) {
                tmp = gifts[i];
                count++;
            }else if(tmp == gifts[i]) {
                count++;
            } else {
                count--;
            }
        }
        count = 0;
        for(int i = 0; i < n; i++) {
            if(gifts[i] == tmp) {
                count++;
            }
        }
        if(count > n / 2) {
            return tmp;
        }
        return 0;
    }
}